#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<climits>
#include<unordered_set>
#include<algorithm>
using namespace std;
int ret;
int n;
int m = INT_MAX;
unordered_set<int>mp;
bool judge(int x)
{
    for (int i = 2; i < x; i++)
    {
        if (x % i == 0) return false;
    }
    return true;
}
void func(vector<int>& v, vector<vector<int>>& vv)
{
    int k = 0;
    for (int i = 0; i < v.size(); i++)
    {
        k = 0;

        for (int j = 2; j <= v[i]; j++)
        {
            if (judge(j) && v[i] % j == 0)
            {

                vv[i].push_back(j);
            }
        }


    }



}
void dfs(vector<vector<int>>& vv, int p)
{


    if (p == n)
    {

        // cout<<'jia';
        // cout<<ret<<' ';

        m = min(m, ret);


        return;
    }
    for (int i = p; i < vv.size(); i++)
    {
        for (int j = 0; j < vv[i].size(); j++)
        {
            if (mp.count(vv[i][j]) == 0)
            {
                //cout<<vv[i][j]<<endl;
                ret += vv[i][j];
                mp.insert(vv[i][j]);

                dfs(vv, i + 1);
                ret -= vv[i][j];
                mp.erase(vv[i][j]);

            }
        }
        break;


    }
}
int main()
{

    cin >> n;
    vector<int>v(n);
    vector<vector<int>>vv(n);

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];

    }
    func(v, vv);


    /*for(int i=0;i<vv.size();i++)
   {
     for(int j=0;j<vv[i].size();j++)
     {
         cout<<vv[i][j]<<' ';
     }

   }*/

    dfs(vv, 0);
    if (m == INT_MAX)
    {
        cout << -1;
    }
    else
    {
        cout << m;
    }





    return 0;
}